package v1

import (
	"gin-blog/middleware"
	"gin-blog/model"
	"gin-blog/utils/msg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Login(c *gin.Context) {
	var user model.User
	var token string
	var code int
	c.ShouldBindJSON(&user)

	code = model.CheckLogin(user.Username, user.Password)

	if code == msg.SUCCESS {
		token, _ = middleware.SetToken(user.Username)
	}
	c.JSON(http.StatusOK, msg.R(code, "token", token))
}
